﻿@page "/config"
@using SqlSugar

@inject IDataService<MattressConfig> db
@inject ToastService tos

@attribute [TabItemOption(Text = "配置", Closable = true)]

<label>@_db?.ErrorInfo</label>

<EditorForm Model="@config" ItemsPerRow="3">
    <Buttons>
        <Button Text="提交" OnClick="@Save"></Button>
    </Buttons>
</EditorForm>

@code {
    MattressConfig? config;
    CustomDataService<MattressConfig>? _db;

    protected override async Task OnInitializedAsync()
    {
        if(db is CustomDataService<MattressConfig> b)
        {
            _db = b;
            config = await _db.GetConfig();
        }
    }

    private async Task Save()
    {
        var res = await _db.SaveConfig(config);
        if (res)
        {
            await tos.Success("成功!");
        }
        else
        {
            await tos.Error("失败！");
        }
    }
}
